package com.gistmap.sideline.web;

import com.gistmap.sideline.dto.LoginDTO;
import com.gistmap.sideline.dto.RegistDTO;
import com.gistmap.sideline.dto.UserAdditionDTO;
import com.gistmap.sideline.response.Result;
import com.gistmap.sideline.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "用户相关接口")
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginDTO dto) {
        return new Result().success(userService.login(dto));
    }

    @ApiOperation(value = "注册")
    @PostMapping("/regist")
    public Result regist(@RequestBody RegistDTO dto) {
        return new Result().success(userService.register(dto));
    }

    @ApiOperation(value = "补充其他信息")
    @PutMapping
    public Result addition(@RequestBody UserAdditionDTO dto){
        userService.addition(dto);
        return new Result().success();
    }

    @ApiOperation(value = "激活")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", dataType = "String"),
            @ApiImplicitParam(name = "code", value = "随机码", dataType = "String")
    })
    @PutMapping("/active")
    public Result active(@RequestParam String code, @RequestParam String token){
        userService.active(code, token);
        return new Result().success();
    }
}
